<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>round</title>
		<link rel="stylesheet" type="text/css" href="/scripts/jquery-easyui-1.6.6/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="/scripts/jquery-easyui-1.6.6/themes/icon.css">
		<script type="text/javascript" src="/scripts/jquery-easyui-1.6.6/jquery.min.js"></script>
		<script type="text/javascript" src="/scripts/jquery-easyui-1.6.6/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="/scripts/jquery-easyui-1.6.6/locale/easyui-lang-zh_CN.js"></script>
		<script type="text/javascript" src="/scripts/project.js"></script>
	</head>

	<script type="text/javascript">
		var pid = localStorage.getItem("pid");
		$(function() {
			$('#rd').datagrid({
				method: 'get',
				url: pro_url + '/rounds?pid=' + pid,
				columns: [
					[{
							field: 'ck',
							checkbox: true
						},
						{
							field: 'result',
							title: '测试结果',
							width: 80
						},
						{
							field: 'name',
							title: '轮次名称',
							width: 280
						},
						{
							field: 'stime',
							title: '开始时间',
							width: 160
						},
						{
							field: 'etime',
							title: '结束时间',
							width: 160
						},
					]
				],
				onDblClickRow: function(index, row) {
					console.log(row)
					window.location.href = 'runlist.html?pid=' + pid + '&rid=' + row.id
				}

			})
		})
	</script>

	<body>
		<table id="rd" class="easyui-datagrid" title="" style="width: 800px; height: 460px" data-options="
			rownumbers:true,singleSelect:true,pagination:true" toolbar="#rdtoolbar">
		</table>

		<div id="rdtoolbar">
			<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add_rd()">新增轮次</a>
			<!--<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit_rd()">编辑轮次</a>-->
			<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="del_rd()">删除轮次</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-large-smartart" plain="true" onclick="start_run()">开始运行</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-large-smartart" plain="true" onclick="rerun()">重跑失败脚本</a>
		</div>

		<div id="adddlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px" closed="true" buttons="#adddlg-buttons">
			<!--<div class="ftitle">Round Information</div>-->
			<form id="ff">
				<div style="margin-bottom:20px">
					<input class="easyui-textbox" name="r_name" id="r_name" style="width:100%" data-options="label:'轮次名称:',required:true">
				</div>
				<div style="margin-bottom:20px">
					<input class="easyui-combobox" name="suite" id="suite" label="数据集:" style="width:100%" data-options="required:true">
				</div>
				<!--<div style="margin-bottom:20px">
					<input class="easyui-combobox" name="cli" id="cli" label="客户端:" style="width:100%">
				</div>-->
				<div style="margin-bottom:20px">
					<input class="easyui-checkbox" name="rerun" id="rerun" label="自动重跑:" value="1">
				</div>
			</form>
		</div>
		<div id="adddlg-buttons">
			<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveRound()">保存</a>
			<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#adddlg').dialog('close')">取消</a>
		</div>

		<script type="text/javascript">
			function sendMsg() {
				var sel = $('#rd').datagrid('getSelected');
				var rid,cli;
				rid=sel.id;
				cli=sel.cli;
				rr=sel.rerun;
				$.ajax({
					url: pro_url+"/startRun?pid="+pid+"&rid="+rid+"&cli="+cli+"&rr="+rr,
					type: "GET",
					success: function(data) {
						console.log(data);
					}
				})
			}

			function start_run() {
				var sel = $('#rd').datagrid('getSelected');
				console.log(sel);
				sendMsg();
			}

			function add_rd() {
				$('#adddlg').dialog('open').dialog('setTitle', '新增测试轮次');
				$('#ff').form('clear');
				$.ajax({
					type: "get",
					url: pro_url + "/suites?pid=" + pid,
					success: function(data) {
						if(data.status==2000) {
							$('#suite').combobox({
								data: data.rows,
								valueField: 'id',
								textField: 'name',
								panelHeight: 'auto'
							})
						}
					}
				})
			}

			function del_rd() {
				var sel = $('#rd').datagrid('getSelected');
				$.ajax({
					type: "get",
					url: "round/del?id=" + sel.id,
					async: true,
					success: function(data) {
						if(data.headers.status == 2000) {
							$('#rd').datagrid('reload')
						}
					}
				});
			}

			function saveRound() {
				$('#ff').form('submit', {
					onSubmit: function() {
						var rname = $('#r_name').val();
						var sid = $('#suite').combobox('getValue');
						var cli = $('#cli').val();
						var rerun = $('[name=rerun]:checked').val();
						var p_data = {
							pid: pid,
							rname: rname,
							sid: sid,
							cli: cli,
							rerun: rerun
						};
						$.ajax({
							type: "post",
							url: "round/add",
							async: true,
							dataType: "json",
							data: JSON.stringify(p_data),
							success: function(data) {
								console.log(data),
									$('#rd').datagrid('reload')
							}
						});
					}
				});
				$('#adddlg').dialog('close')
			}
		</script>

	</body>

</html>